package zy02;

import java.lang.reflect.Method;
import java.lang.reflect.Parameter;

/**
 * @Author czl
 * @Date 2024-04-03
 */
public class MainTest {
    public static int sum(int num) throws Exception {
        Class<?> clazz = Sum.class;

        Method method = clazz.getMethod("getSum", int.class);

        Parameter[] parameters = method.getParameters();

        Parameter parameter = parameters[0];

        if (parameter.isAnnotationPresent(Max.class)){
            int value = parameter.getAnnotation(Max.class).value();
            if (num>value){
                throw  new RuntimeException("对不起，我只能最多处理 1-" + value + "之间的和！");
            }
        }
        return Sum.getSum(num);
    }

    public static void main(String[] args) throws Exception {
        System.out.println(sum(69));
    }
}
